package com.gsafety.wellsfort.config;


import com.gsafety.wellsfort.interceptor.AuthenticationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器 拦截所有 api请求
 * @author tangjiawei
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    /**
     * 将自定义拦截器注册到spring bean中
     */
    @Bean
    public AuthenticationInterceptor authenticationInterceptor() {
          return new AuthenticationInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor()).addPathPatterns("/api/**");
    }
}
